package com.google.android.apps.skipbot;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import android.content.Context;

public class Pose implements Serializable {
  private static final long serialVersionUID = 7387244829034752127L;
  Map<Integer, Integer> positions;

  public Pose() {
    positions = new HashMap<Integer, Integer>();
  }

  public void setServo(int servoIndex, int servoPosition) {
    positions.put(servoIndex, servoPosition);
  }

  public boolean save(Context context, String poseName) {
    return Utilities.saveObject(context, poseName, this);
  }

  public static Pose load(Context context, String poseName) {
    return (Pose) Utilities.loadObject(context, poseName);
  }

  public int size() {
    return positions.size();
  }

  /**
   * @return the list of set servos in this pose.
   */
  public Set<Integer> getServoList() {
    return positions.keySet();
  }

  public int getPosition(Integer servoNumber) {
    if (positions.containsKey(servoNumber)) {
      return positions.get(servoNumber);
    }
    return -1;
  }
}
